package dfbz.homework1;

public class Test08 {
    public static void main(String[] args) {
        String str="javajfiewjavajfiowfjavagkljjava";
        int i = getCount(str, "java");
        System.out.println("java出现的次数为:"+i+
                "次");
    }
    public static int getCount(String str, String ch){
//定义一个int类型变量count，用来记录查找到ch字符串的次数
        int count=0;
        while (str.indexOf(ch) != -1){
            int index=str.indexOf(ch);
            str=str.substring(index+ch.length());
            count++;
        }
        return count;
    }
}
